{% extends 'website/backend/backend_base.html' %}
{% block option-title %}
    分类列表
{% endblock %}
{% block content %}
    <div class="col-md-12">
        <table class="table table-hover table-responsive table-condensed dashboard-table">
            <thead>
                <tr>
                    <th>序号</th>
                    <th>类别名称</th>
                    <th>动作</th>
                </tr>
            </thead>
            <tbody>
                {% for item in category_list %}
                    <tr>
                        <td>{{ forloop.counter }}</td>
                        <td>{{ item.name }}</td>
                        <td>
                            <a href="{% url 'category-update' item.pk %}" class="btn btn-warning" role="button">修改</a>
                            &emsp;
                            <button class="btn btn-danger" role="button" data-id="{{ item.id }}">删除</button>
                        </td>
                    </tr>
                {% endfor %}
            </tbody>
        </table>
    </div>
    {% include 'utils/modal.html' %}
{% endblock %}
{% block js %}
     <script type="text/javascript">
        $('.btn-danger').on('click',function (e){
            e.preventDefault()
            var  dom_item =this
            $.ajax({
                type:"POST",
                dataType:"json",
                data:{},
                url:"{% url "category-delete" 00%}".replace('0',this.dataset['id']),
                success:function (data){
                    var state = data.state
                    if (state === 'success'){
                        dom_item.parentElement.parentElement.setAttribute('hidden','')
                        showModal('success','删除成功')
                    }else {
                        showModal('danger','删除失败')
                    }
                },
                error:function (data){
                    console.log(data)
                }
            })
        })
    </script>
{% endblock %}